Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kernel] Prototype integration of bytedance/flux kernels #5917

Closed
wants to merge 11 commits into from

Conversation

tlrmchlsmth
Copy link
Collaborator

@tlrmchlsmth tlrmchlsmth commented Jun 27, 2024

Summary

This is a rough prototype integration of the fused Gemm-ReduceScatter and AllGather-Gemm kernels from https://github.com/bytedance/flux.

The overall goal is to improve performance in the multi-GPU case by hiding the latency of collective communications by overlapping compute and data movement.

Instructions

To use this PR, first follow the instructions from the flux repo to build a wheel and then install it. You will also need to source the flux_env.sh file included in this PR. I had to manually set LD_LIBRARY_PATH to contain my venv's lib directory as well.

Performance

I am running the following to measure the latency of a request dominated by a large prefill:

python3 benchmarks/benchmark_latency.py --model meta-llama/Meta-Llama-3-8B-Instruct \
    --num-iters 100  --batch-size 1 --input-len 2048 --output-len 1 \
    --enforce-eager --tensor-parallel-size 4 --dtype float16

On 4 A100's:

This PR:

Avg latency: 0.04923512919805944 seconds
10% percentile latency: 0.048771245032548906 seconds
25% percentile latency: 0.04908173996955156 seconds
50% percentile latency: 0.04925268283113837 seconds
75% percentile latency: 0.04937761859036982 seconds
90% percentile latency: 0.04951343145221472 seconds
99% percentile latency: 0.050627540834248065 seconds

main:

Avg latency: 0.05624247697182 seconds
10% percentile latency: 0.05587919522076845 seconds
25% percentile latency: 0.05596787924878299 seconds
50% percentile latency: 0.05612784903496504 seconds
75% percentile latency: 0.05637543648481369 seconds
90% percentile latency: 0.05679564494639635 seconds
99% percentile latency: 0.05786421288736165 seconds

PR Checklist (Click to Expand)

Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Model] for adding a new model or improving an existing model. Model name should appear in the title.
  • [Frontend] For changes on the vLLM frontend (e.g., OpenAI API server, LLM class, etc.)
  • [Kernel] for changes affecting CUDA kernels or other compute kernels.
  • [Core] for changes in the core vLLM logic (e.g., LLMEngine, AsyncLLMEngine, Scheduler, etc.)
  • [Hardware][Vendor] for hardware-specific changes. Vendor name should appear in the prefix (e.g., [Hardware][AMD]).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to docs/source/ if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.

Notes for Large Changes

Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with rfc-required and might not go through the PR.

What to Expect for the Reviews

The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

Thank You

Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!

@Rainlin007
Copy link

Tested in 13B model, it is more than 40% slower than the main branch. Is there a better optimization solution? Thanks

@tlrmchlsmth
Copy link
Collaborator Author

@Rainlin007 Could you share your test setup and numbers?

There are a couple of things that can be done to improve this PR's performance:

  1. The call to self.ag_gemm_op.reset_signals can be removed now that feat: fix tuning for the all-gather gemm && move the reset-signal() to the forward critical path bytedance/flux#19 has landed
  2. The argument fuse_reduction=True to the GemmRS kernel should be changed to False, but I am running into issues with that (see [BUG] Illegal memory access when fuse_reduction=False bytedance/flux#10)

After that, I think we'll see speedup on prefills and hopefully large batch size decodes.

@zheng-ningxin
Copy link

Tested in 13B model, it is more than 40% slower than the main branch. Is there a better optimization solution? Thanks

Which shape/model are you using? It’s possible that the default GEMM configuration performs poorly at this size. I can retune a GEMM configuration. Thank you.

@tlrmchlsmth
Copy link
Collaborator Author

@zheng-ningxin, @Rainlin007's comment was also posted on an earlier version of this PR, so @Rainlin007 you might want to try again now that I'm seeing speedup on my end.

@wenlei-bao
Copy link

wenlei-bao commented Aug 12, 2024

Hey @tlrmchlsmth, is there any blocking issue to merge this PR (other than the format issue)? Please let us know if anything we could help to make this happen. :) cc @zheng-ningxin
Best.

@tlrmchlsmth
Copy link
Collaborator Author

Hey @wenlei-bao, one blocking issue is that this PR requires enforce_eager be true. That is, the last time I tried it, the Flux kernels don't support CUDA graphs. Do you know if this is still the case?

Beyond that, I need to do some benchmarking and develop some heuristics to decide when this optimization makes sense. The other thing worth mentioning is that ultimately, we don't want to rely on changing the model definition for the integration of the Flux kernels, but I think that the torch.compile rewrites are going slowly enough that it shouldn't block this PR from landing.

@Pinkypoopoo
Copy link

Pinkypoopoo commented Aug 13, 2024 via email

@wenlei-bao
Copy link

Hey @wenlei-bao, one blocking issue is that this PR requires enforce_eager be true. That is, the last time I tried it, the Flux kernels don't support CUDA graphs. Do you know if this is still the case?

Yes, we don't support/need CUDA graph yet.

Beyond that, I need to do some benchmarking and develop some heuristics to decide when this optimization makes sense.

Regarding the heuristics, you might also want to explore the scripts that in Flux tools/ folder for tuning different workloads (if apply), and incorporate different tiling choices for example to your heuristics (if to skip) or (in Flux tuning_config/ config files
if you want to config and apply Flux) as well to maximize the performance.

The other thing worth mentioning is that ultimately, we don't want to rely on changing the model definition for the integration of the Flux kernels, but I think that the torch.compile rewrites are going slowly enough that it shouldn't block this PR from landing.

Sounds great! Looking forward to it. @tlrmchlsmth

@tlrmchlsmth
Copy link
Collaborator Author

Abandoning this in favor of #9886!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants